package com.yy.permissions_general.common.config.error;

import org.springframework.boot.web.server.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;

/**
 * @program: permissions_general
 * @description: 自定义错误页面页面
 * @author: YY
 * @create: 2021-03-23 22:14
 **/
@Configuration
public class ErrorPageConfig {
    @Bean
    public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer() {
        WebServerFactoryCustomizer<ConfigurableWebServerFactory> webCustomizer = new WebServerFactoryCustomizer<ConfigurableWebServerFactory>() {
            @Override
            public void customize(ConfigurableWebServerFactory factory) {
                ErrorPage[] errorPages = new ErrorPage[] {
                        new ErrorPage(HttpStatus.FORBIDDEN, "/view/error/403"),
                        new ErrorPage(HttpStatus.NOT_FOUND, "/view/error/404"),
                        new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/view/error/500"),
                };
                factory.addErrorPages(errorPages);
            }
        };
        return webCustomizer;
    }
}
